Skip to content

Conversation

@joyewon0705
Copy link
Collaborator

📌 개요

  • 게시판 도메인 내 내 게시글 / 내 댓글 / 내 북마크 게시글 목록 조회 로직을 QueryDSL 기반으로 개선하였습니다.
  • 각 조회 로직에서 발생하던 N+1 문제를 해소하고, 불필요한 엔티티 접근을 최소화하여 성능을 최적화했습니다.

🔨 작업 내용

1. 내 게시글 목록 조회 개선 (PostRepositoryImpl)

  • 기존 findAllByUserId()findPostsByUserId() (QueryDSL 기반)
  • 조회 시 User, UserProfile 조인을 통해 작성자 정보 즉시 조회
  • 게시글별 카테고리 목록은 IN 쿼리 1회로 주입하여 N+1 제거
  • 정렬 조건 화이트리스트 기반(createdAt, likeCount, bookmarkCount)

2. 내 댓글 목록 조회 개선 (CommentRepositoryImpl)

  • 기존 JPA 단순 조회(findAllByUserId) 제거 → findCommentsByUserId() 추가
  • Comment, Post, Parent Comment를 조인하여 단일 쿼리로 댓글 및 상위 댓글 정보 조회
  • 부모 댓글 내용은 최대 50자까지만 잘라서 반환
  • 불필요한 N+1 제거 및 정렬 조건 화이트리스트 적용

3. 내 북마크 게시글 목록 조회 개선 (PostRepositoryImpl)

  • 기존 PostBookmarkRepository 직접 접근 제거
  • QueryDSL 기반 findBookmarkedPostsByUserId() 추가
  • 북마크된 게시글을 기준으로 Post, User, UserProfile 조인 조회
  • 카테고리 목록은 별도 IN 쿼리로 1회 조회

4. DTO 및 Service 정리

  • PostListResponse, MyCommentResponse의 정적 팩토리 제거 → @QueryProjection 기반 생성자 사용
  • UserService 내 관련 메서드(getMyPosts, getMyComments, getMyBookmarks)에서 QueryDSL 기반 메서드 호출로 교체

5. 테스트

  • PostRepositoryImpl, CommentRepositoryImpl 관련 테스트 케이스 추가
  • UserControllerTest 관련 테스트 케이스 개선

🔗 관련 이슈

Closes #{이슈 번호}

📝 참고 사항

  • QueryDSL 기반 DTO 매핑 구조(QPostListResponse, QMyCommentResponse)로 변경되어 IDE 빌드 시 Q타입 재생성 필요

✅ 체크리스트

  • 기능 동작 확인
  • 테스트 코드 작성
  • 문서/주석 추가 및 최신화

@github-actions github-actions bot changed the title Refactor: 내 게시글/댓글/북마크 목록 조회 QueryDSL 기반 개선 Refactor: 내 게시글/댓글/북마크 목록 조회 QueryDSL 기반 개선 (#245) Oct 13, 2025
@joyewon0705 joyewon0705 merged commit eb34299 into dev Oct 13, 2025
3 checks passed
@github-actions github-actions bot deleted the Refactor/245 branch October 13, 2025 06:18
@joyewon0705 joyewon0705 restored the Refactor/245 branch October 13, 2025 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants